function ApplyInfo() {
    this.method, this.action;
}
function getFormParams(){
	var params = $('#inputForm').serializeJson();
	if(!params.applyId){//报备ID
		params.applyId = 0;
	}
	if(!params.houseId){//房源ID
		params.houseId = 0;
	}
	if(!params.applyStatus){//报备状态
		params.applyStatus = 0;
	}
	return params;
}
ApplyInfo.prototype.load = function (params) {
    var objThis = this;
    var params = getFormParams();
    $('#datagrid_applyInfo').datagrid({
        url: basePath + '/' + this.action + '/' + objThis.method,
        fitColumns: true,
        striped: true,
        pagination: true,
        rownumbers: true,
        pageSize: 50,
        pageNumber: 1,
        pageList: [20, 50, 100],
        loadMsg: '数据正在加载中...',
        queryParams: params,
        singleSelect: true,
        selectOnCheck: false,
        checkOnSelect: false,
        columns: [[
            {
                field: 'applyId',
                title: '<span class="txtcenter">报备ID</span>',
                resizable: true,
                hidden: false,
                sortable: false,
                width: '7%',
                align: 'center',
                formatter: function(v, row) {
                	//补齐8位数字
                	var applyId = row.applyId;
                	var leftLength = (8 - (applyId + '').length);
                	for(var i=0; i<leftLength; i++){
                		applyId = '0' + applyId;
                	}
                	return applyId;
                }
            },
            {
                field: 'houseId',
                title: '<span class="txtcenter">House ID</span>',
                resizable: true,
                hidden: false,
                sortable: false,
                width: '7%',
                align: 'center'
            },
            {
                field: 'districtAndTown',
                title: '<span class="txtcenter">行政区-板块</span>',
                resizable: true,
                hidden: false,
                sortable: true,
                width: '9%',
                align: 'center'
            },
            {
                field: 'estateName',
                title: '<span class="txtcenter">小区名称</span>',
                resizable: true,
                hidden: false,
                sortable: false,
                width: '9%',
                align: 'center'
            },
            {
                field: 'address',
                title: '<span class="txtcenter">房源地址</span>',
                resizable: true,
                hidden: false,
                sortable: false,
                width: '10%',
                align: 'center'
            },
            {
                field: 'buildingNum',
                title: '<span class="txtcenter">楼栋</span>',
                resizable: true,
                hidden: false,
                sortable: false,
                width: '3%',
                align: 'center'
            },
            {
                field: 'room',
                title: '<span class="txtcenter">室号</span>',
                resizable: true,
                hidden: false,
                sortable: false,
                width: '3%',
                align: 'center'
            },
            {
                field: 'source',
                title: '<span class="txtcenter">渠道</span>',
                resizable: true,
                hidden: false,
                sortable: false,
                width: '3%',
                align: 'center',
                formatter: function(v, row) {
                	//1.IW;2.房管JAZ
                	if(row.source == 1){
                		return "IW";
                	}else if(row.source == 1){
                		return "房管";
                	}
                }
            },
            {
                field: 'creatorInfo',
                title: '<span class="txtcenter">发布者</span>',
                resizable: true,
                hidden: false,
                sortable: false,
                width: '10%',
                align: 'center'
            },
            {
                field: 'focusAgentInfo',
                title: '<span class="txtcenter">房管经纪人</span>',
                resizable: true,
                hidden: false,
                sortable: false,
                width: '10%',
                align: 'center'
            },
            {
                field: 'applyStatus',
                title: '<span class="txtcenter">报备状态</span>',
                resizable: true,
                hidden: false,
                sortable: false,
                width: '7%',
                align: 'center',
                formatter: function(v, row) {
                	//1成功  2报备中  3报备失败
                	if(row.applyStatus == 1){
                		return "审核成功";
                	}else if(row.applyStatus == 2){
                		return "审核中";
                	}if(row.applyStatus == 3){
                		return "审核失败";
                	}
                }
            },
            {
                field: 'applyTime',
                title: '<span class="txtcenter">报备时间</span>',
                resizable: true,
                hidden: false,
                sortable: false,
                width: '8%',
                align: 'center'
            },
            {
            	field: 'action',
                title: '<span class="txtcenter">详情</span>',
                resizable: true,
                hidden: false,
                sortable: false,
                width: '7%',
                align: 'center',
                formatter: function(v, row) {
                    var params = "";
                    var d = "<a href='" + basePath + "/apply/getApplyDetail?applyId=" + row.applyId + "' target='CONTRACT_" + row.id + "''>详情</a>";
                    return d;
                }
            }
        ]],
        onLoadSuccess: function (data) {
            //validateReqStatus(data);
        },
        onLoadError: function (data) {
            //validateReqStatus(data);
        }
    });
};

ApplyInfo.prototype.init = function () {
    var objThis = this;
    objThis.load();
};
//加载报备信息
function loadApplyInfo(){
	var applyInfo = new ApplyInfo();
    applyInfo.action = "apply";
    applyInfo.method = "getApplyInfos";
    applyInfo.init();
}

$(document).ready(function () {
	loadApplyInfo();
    $("#searchBtn").click(loadApplyInfo);
});
